/*
 * File Name: StatusBarMessage.java
 */

package co.edu.uniandes.intercon.client.model;

import java.util.Observable;

/**
 * <code>Singleton</code> used to store the message shown in the status bar 
 * component
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class StatusBarMessage extends Observable {
    
    /*
     * Singleton instance 
     */
    private static StatusBarMessage instance;
    
    /*
     * current message
     */
    private String message;
    
    /*
     * visibility of the message
     */
    private boolean hidden;
    
    /*
     * Visibility mode used to hide or show the message
     */
    public static final String UPDATE_MODE_HIDE = "hide";
    
    /*
     * Text mode used to refresh the content of the message bar component
     */
    public static final String UPDATE_MODE_MESSAGE = "message";
    
    // avoids instantiation outside the class
    private StatusBarMessage() {}
    
    /** Creates a new instance of StatusBar */
    public static synchronized StatusBarMessage getInstance() {
        if (instance==null) {
            instance = new StatusBarMessage();
        }
        return instance;
    }
    
    /**
     * Retrieves current message
     * @return current message
     */
    public String getMessage() {
        return message;
    }
    
    /**
     * Set the current message and notity all the observers of this class about 
     * the change
     * @param   message Message to be set
     */
    public void setMessage(String message) {
        this.message = message;
        super.setChanged();
        super.notifyObservers(UPDATE_MODE_MESSAGE);
    }
    
    /**
     * Retrieves the current visibility
     * @return <code>true</code> is is visible and <code>false</code> otherwise
     */
    public boolean isHidden() {
        return hidden;
    }
    
    /**
     * Set the current visibility and notity all the observers of this class 
     * about the change
     * @param   hidden  visibility of the message
     */
    public void setHidden(boolean hidden) {
        this.hidden = hidden;
        super.setChanged();
        super.notifyObservers(UPDATE_MODE_HIDE);
    }
    
}
